const joi = require('joi');

const loginname = joi.string().pattern(/^[\S]{1,5}$/).required()
const password = joi.string().pattern(/^[\S]{5,12}$/).required()
const username = joi.string().pattern(/^[\S]{1,5}$/).required()

exports.userCheck = {
    body: {
        loginname,
        password,
        username
    }
}

exports.loginCheck = {
    body: {
        loginname,
        password
    }
}

// 用户管理查询的校验规则
const Search = joi.string().optional();
const page = joi.number().integer().required();
const size = joi.number().integer().required();
exports.findUserListCheck = {
    query: {
        Search,
        page,
        size
    }
}

// 用户管理修改的校验规则
const img = joi.string().optional();
const id = joi.number().integer().required();
exports.updateUserListCheck = {
    query: {
        id,
        loginname,
        username,
        img
    }
}

// 用户管理删除的校验规则
exports.deleteUserListCheck = {
    query: {
        id
    }
}

// 栏目管理查询的接口
exports.columnListCheck = {
    query: {
        Search,
        page,
        size
    }
}

// 栏目修改的接口
const name = joi.string().required()
const orderby = joi.number().integer().required();
const type = joi.number().integer().required();
const content = joi.string().optional();
exports.updateColumnListCheck = {
    query: {
        id,
        name,
        orderby,
        type,
        content,
    }
}

// 栏目添加的接口
exports.addColumnListCheck = {
    body: {
        name,
        orderby,
        type,
        content,
    }
}

// 栏目管理删除的校验规则
exports.deleteColumnListCheck = {
    query: {
        id
    }
}

// 内容管理查询的接口
exports.contentListCheck = {
    query: {
        Search,
        page,
        size
    }
}

// 内容添加接口
const contents = joi.string().required();
const author = joi.string().required();
const cms_columnId = joi.number().integer().required();
exports.addContentListCheck = {
    body: {
        name,
        orderby,
        author,
        contents,
        cms_columnId
    }
}

// 内容修改接口
exports.updateContentListCheck = {
    query: {
        id,
        name,
        orderby,
        author,
        contents,
        cms_columnId
    }
}

// 内容管理删除的校验规则
exports.deleteContentListCheck = {
    query: {
        id
    }
}